<template>
  <div>
    <el-card class="top"><el-header>加息券记录</el-header></el-card>

    <!-- 表格展示 -->
    <el-card>
      <el-input placeholder="加息券名称" prefix-icon="el-icon-search" style="width: 200px" v-model="name">
      </el-input>
      <el-button type="warning" @click="reload" plain>查询</el-button>
      
      <el-table :data="List" style="width: 100%" :sort-by.sync="sortKey" :sort-orders="['ascending', 'descending']">
        <el-table-column type="index" label="编号" width="50" align="center">
        </el-table-column>
        <el-table-column prop="uname" label="用户名" width="90" align="center">
        </el-table-column>
        <el-table-column prop="name" label="真实姓名" width="80" align="center">
        </el-table-column>
        <el-table-column prop="vname" label="加息券名称" width="90" align="center">
        </el-table-column>
        <el-table-column prop="increase" label="加息率(%)" width="90" align="center">
        </el-table-column>
        <el-table-column prop="money" label="使用金额起始值" width="150" align="center " sortable>
        </el-table-column>
        <el-table-column prop="start" label="期限起始值(天)" width="120" align="center">
        </el-table-column>
        <el-table-column prop="time" label="加息时长(天)" width="110" align="center">
        </el-table-column>
        <el-table-column prop="type" label="类型限制" width="80" align="center">
        </el-table-column>
        <el-table-column prop="expiredtime" label="有效期(天)" width="120" align="center" sortable>
        </el-table-column>
        <el-table-column prop="geytime" label="获取时间" width="160" align="center" sortable>
        </el-table-column>
        <el-table-column prop="usetime" label="使用时间" width="160" align="center" sortable>
        </el-table-column>
        <el-table-column prop="state" label="状态" width="70" align="center">
        </el-table-column>
      </el-table>
    </el-card>

    <!--    分页-->
    <el-row>
      <el-col style="text-align:right">
        <el-pagination :current-page="currentPage" @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :page-size="pageSize" :page-sizes="[5, 10, 15]" layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </el-col>
    </el-row>
  </div>

</template>

<script>
import { del } from 'vue';

export default {
  data() {
    return {
      name: "",
      sortKey: '',
      List: [],
      formLabelWidth: '120px',
      //配置分页
      currentPage: 1,
      pageSize: 5,
      total: 0
    };
  },


  mounted() {
    this.reload();
  },

  methods: {
    // 查询列表
    reload() {
      this.$axios.get("/vouchersrecord/findAll?currentPage=" + this.currentPage + "&pageSize=" + this.pageSize + "&name=" + this.name).then((res) => {
        console.log(res.data.data);
        this.List = res.data.data.list;
        this.total = res.data.data.total;
      });
    },
    // 显示查询出的总条数
    handleSizeChange(val) {
      this.pageSize = val;
      this.reload();
    },

    // 点击新页查询的数据
    handleCurrentChange(val) {
      this.currentPage = val;
      this.reload();
    },

    // 编辑
    handleEdit(row) {
      this.editform = { ...row };
    },
  },
};
</script>

<style scoped>
.el-header {
  text-align: center;
  line-height: 30px;
  size: 120px;
}

.top {
  background-color: #D3D3D3;
  height: 60px;
}

.el-card {
  margin-top: 10px;
  margin-left: 30px;
}

.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>